package br.com.ufc.apsoo.hotelar.controller;

import java.util.List;

import javax.faces.model.DataModel;
import javax.faces.model.ListDataModel;

import br.com.ufc.apsoo.hotelar.dao.ServicoDao;
import br.com.ufc.apsoo.hotelar.dao.impl.ServicoDaoImpl;
import br.com.ufc.apsoo.hotelar.model.Servico;

public class ServicoController {
	private Servico servico;
	private DataModel<Servico> listaServicos;

	public DataModel<Servico> getListarServicos() {
		List<Servico> lista = new ServicoDaoImpl().list();
		listaServicos = new ListDataModel<Servico>(lista);
		return listaServicos;
	}

	public Servico getServico() {
		return servico;
	}

	public void setServico(Servico servico) {
		this.servico = servico;
	}

	public String prepararAdicionarServico() {
		servico = new Servico();
		return "cadastro_servico";
	}

	public String prepararAlterarServico() {
		servico = listaServicos.getRowData();
		return "edicao_servico";
	}

	public String excluirServico() {
		Servico servicoTemp = (Servico) (listaServicos.getRowData());
		ServicoDao dao = new ServicoDaoImpl();
		dao.remove(servicoTemp);
		return "gerenciador_servico";
	}

	public String adicionarServico() {
		ServicoDao dao = new ServicoDaoImpl();
		dao.save(servico);
		return "gerenciador_servico";
	}

	public String alterarServico() {
		ServicoDao dao = new ServicoDaoImpl();
		dao.update(servico);
		return "gerenciador_servico";
	}

}
